//
//  HanViewController.m
//  HIGHT
//
//  Created by 夜空 on 2017/10/24.
//  Copyright © 2017年 夜空. All rights reserved.
//
#import "TongCollectionViewCell.h"
#import "TongViewController.h"
#import "Masonry/Masonry.h"
#import "HanViewController.h"
#import <AVFoundation/AVFoundation.h>
@interface HanViewController ()<UICollectionViewDataSource,UICollectionViewDelegate,UICollectionViewDelegateFlowLayout>
@property (nonatomic,strong)UICollectionView *collectionV;

@end

@implementation HanViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title=@"导航栏";
    self.navigationItem.backBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"返回" style:UIBarButtonItemStylePlain target:nil action:nil];
    self.view.backgroundColor=[UIColor whiteColor];
    [self subview];
    
    
    
    
  
    
    // Do any additional setup after loading the view.
}
- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    
    [self.navigationController setNavigationBarHidden:YES animated:YES];
}

- (void)viewWillDisappear:(BOOL)animated {
    [super viewWillDisappear:animated];
    
    [self.navigationController setNavigationBarHidden:NO animated:YES];
} 
-(void)subview{
    UIButton * btn=[UIButton buttonWithType:UIButtonTypeCustom];
    btn.frame=CGRectMake(0, 44, 320, 40);
    [btn setTitle:@"返回" forState:UIControlStateNormal];
     ;
    [btn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    btn.titleLabel.font=[UIFont systemFontOfSize:15];
    [btn addTarget:self action:@selector(back) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:btn];
    
    
    
    UIButton * nextbtn=[UIButton buttonWithType:UIButtonTypeCustom];
    [nextbtn setTitle:@"下一页" forState:UIControlStateNormal];
    [nextbtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    nextbtn.titleLabel.font=[UIFont systemFontOfSize:20];
    nextbtn.backgroundColor=[UIColor greenColor];
    [nextbtn addTarget:self action:@selector(nextbtn) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:nextbtn];
    [nextbtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.mas_equalTo(self.view.mas_bottom);
        make.left.mas_equalTo(0);
        make.width.mas_equalTo(UISCREEN_WIDTH);
        make.height.mas_equalTo(40);
    }];
    
    [nextbtn mas_updateConstraints:^(MASConstraintMaker *make) {
        make.bottom.mas_equalTo(0);
        make.left.mas_equalTo(0);
    }];
    
    
    UILabel * label=[[UILabel alloc] init];
    label.frame=CGRectMake(10, 100, 300, 40);
    label.text=@"不萨哈是打你架按理卡大两岁打你山建华大街";
    label.textColor=[UIColor blueColor];
    NSRange range;
    range = [@"不萨哈是打你架按理卡大两岁打你山建华大街" rangeOfString:@"打你"];
    label.font=[UIFont systemFontOfSize:15];
    [self fuwenbenLabel:label FontNumber:[UIFont systemFontOfSize:15] AndRange:range AndColor:[UIColor greenColor]];
    [self.view addSubview:label];
    
    UICollectionViewFlowLayout *layout = [UICollectionViewFlowLayout new];
    layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
    layout.minimumLineSpacing = 2;
    _collectionV = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 200, UISCREEN_WIDTH, 40) collectionViewLayout:layout];
    [_collectionV setBackgroundColor:[UIColor whiteColor]];
    
    
    _collectionV.delegate = self;
    _collectionV.dataSource = self;
    _collectionV.showsVerticalScrollIndicator = NO;
    _collectionV.showsHorizontalScrollIndicator = NO;
    [_collectionV registerClass:[TongCollectionViewCell class] forCellWithReuseIdentifier:@"FOOD_CELL_ID"];
    [self.view addSubview:_collectionV];
   
    NSString *version = [UIDevice  currentDevice].systemVersion;
    if (version.doubleValue >= 9.0) {
        // 针对 9.0 以上的iOS系统进行处理
    } else {
        // 针对 9.0 以下的iOS系统进行处理
    }
    
    
    UIButton * button=[UIButton buttonWithType:UIButtonTypeCustom];
    [button setTitle:@"" forState:UIControlStateNormal];
    [button addTarget:self action:@selector(boon:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:button];
    
}
-(void)boon:(UIButton *)sender{
    
    
    
    
}
-(void)fuwenbenLabel:(UILabel *)labell FontNumber:(id)font AndRange:(NSRange)  range AndColor:(UIColor *)vaColor
{
    NSMutableAttributedString *str = [[NSMutableAttributedString alloc] initWithString:labell.text];
    //设置字号
    [str addAttribute:NSFontAttributeName value:font range:range];
    //设置文字颜色
    [str addAttribute:NSForegroundColorAttributeName value:vaColor range:range];
    labell.attributedText = str;
}
-(void)nextbtn{
    
    TongViewController * tong = [[TongViewController alloc] init];
    [self.navigationController pushViewController:tong animated:YES];
    
}
-(void)back{
    
    [self.navigationController popViewControllerAnimated:YES];
    
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    NSArray * arr=@[@"拉克下再绞尽脑汁想疾控中心丝",@"阿拉山口西安开",@"爱上联系啊",@"拉枯折朽吗",@"暗示今年下"];

    return [arr count];
}


- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    TongCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"FOOD_CELL_ID" forIndexPath:indexPath];
    
    NSArray * arr=@[@"拉克下再绞尽脑汁想疾控中心丝",@"阿拉山口西安开",@"爱上联系啊",@"拉枯折朽吗",@"暗示今年下"];
    
    
    [cell refreshData:arr[indexPath.row]];
    return cell;
}


- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{
    NSArray * arr=@[@"拉克下再绞尽脑汁想疾控中心丝",@"阿拉山口西安开",@"爱上联系啊",@"拉枯折朽吗",@"暗示今年下"];
    NSString *str=arr[indexPath.row];
    return CGSizeMake([self width:str]+20, 40);
}


- (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout insetForSectionAtIndex:(NSInteger)section
{
    return UIEdgeInsetsMake(0,0,0,0);
}

-( void )collectionView:( UICollectionView *)collectionView didSelectItemAtIndexPath:( NSIndexPath *)indexPath{




}
-(CGFloat)width:(NSString*)str{
    
    UILabel * label=[[UILabel alloc] init];
    label.backgroundColor=[UIColor cyanColor];
    label.text=str;
    label.numberOfLines=1;
    label.font=[UIFont systemFontOfSize:15];
    CGRect rect = [label.text boundingRectWithSize:CGSizeMake(MAXFLOAT, 40) options:NSStringDrawingUsesLineFragmentOrigin|NSStringDrawingUsesFontLeading attributes:@{NSFontAttributeName: label.font} context:nil];
    NSLog(@"%f",rect.size.width);
    return rect.size.width;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
